using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace DD.Pages
{
    public partial class UploadProductImage : System.Web.UI.Page
    {
        private int ProductId;
        protected void Page_Load(object sender, EventArgs e)
        {
            //ProductId = Convert.ToInt32(Request["PID"]);
            ProductId = 1;
            Button2.Attributes.Add("onclick", "javascript:closeWindow();");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string path = "~/ProductImages";
            //string ext = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf("."), FileUpload1.PostedFile.FileName.Length -1);

            string[] exts = FileUpload1.PostedFile.FileName.Split('.');
            string ext = exts[exts.Length - 1];
            
            string filename = DateTime.Now.Ticks.ToString();
            filename += "." + ext;

            string filepath = System.IO.Path.Combine(path, filename);
            FileUpload1.PostedFile.SaveAs(Server.MapPath(filepath));

            Label2.Text = "File Successfully Uploaded";

            DD.Imaging.ImageManager.AddImageToProduct(ProductId, filename);

            
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
           // Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CloseWindow", "closeWindow()", true);

        }
    }
}
